package com.le.mvc.controller;

import com.le.mvc.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/users")
public class HelloController {

    //    @RequestMapping(value = "add",method=RequestMethod.POST)
//    上面的语句相当于下面
//    @PostMapping("add")
//    public String add(){
//        return "users/add";
//    }
//    //必须传参才能访问，加入token后，必须带着token才能访问
//    @PostMapping(value = "add",params = {"name"},headers = {"token"})
//    public String add(HttpServletRequest request,Model model) {
//        String name=request.getParameter("name");
//        model.addAttribute("name",name);
//        System.out.println(name);
//        return "users/add";
//    }
//    //向页面传递数据
//    @RequestMapping(value = "list", method = RequestMethod.GET)
//    public String hello(@RequestParam(value = "m",required = false) String name ,
//                        User user, Model model) {
//        System.out.println(user);
//        System.out.println(name);
//        model.addAttribute("name", name);
//        return "users/list";
//    }
    //向页面传递数据
    @PostMapping(value = "add", headers = {"token"})
    public String hello(@RequestBody User user) {
        System.out.println(user.getName());
        System.out.println(user.getAge());
        return "users/add";
    }
}
